const db = require('../DBcofig/f_DBConnection')
module.exports = {
    getTable(req, resp) {
        //每页多少条
        let { a, b } = req.query
        let arr = [(JSON.parse(a) - 1) * b, JSON.parse(b)]
        let sql = 'select * from cz_topup limit ?,?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    tableLength(req, resp) {
        let sql = 'select * from cz_topup '
        db.f_DBConnection(resp, sql, [], function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    setSize(req, resp) {
        let text = req.body.page
        let arr = [text, text]
        let sql = 'select * from cz_topup where cz_name = ? OR cz_id = ?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    getTime(req, resp) {
        let { time, time1 } = req.body
        console.log(time, time1);
        let sql = 'select * from cz_topup where cz_time > ? AND cz_time < ?'
        let arr = [time, time1]
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },

    addTable(req, resp) {

        let table = req.query
        let sql = 'select * from cz_topup'
        let arr = []
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '导入成功',
                data: table
            })
        })
    },
    setDetails(req, resp) {
        let id = req.body.id
        let arr = [id]
        let sql = 'select * from cz_topup left join czxq_topup on cz_id=czxq_id where cz_id=?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    node(req, resp) {
        let { id, note } = req.body
        console.log(req.body);
        let arr = [note, id]
        console.log(arr);
        let sql = 'update czxq_topup set czxq_note=? where czxq_id=?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '备注成功',
                data: data
            })
        })
    },
    refund(req, resp) {
        let { a, b } = req.query
        let arr = [JSON.parse(a - 1) * b, a * b]
        let sql = 'select * from tk_topup limit ?,?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    refundPage(req, resp) {
        let arr = []
        let sql = 'select * from tk_topup'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    setTkSize(req, resp) {
        let text = req.body.text
        let arr = [text, text]
        let sql = 'select * from tk_topup where tk_name= ? OR tk_id= ?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    getTime1(req, resp) {
        let { time, time1 } = req.body
        console.log(time, time1);
        let sql = 'select * from tk_topup where tk_time > ? AND tk_time < ?'
        let arr = [time, time1]
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    setPefund(req, resp) {
        let id = req.body.id
        let arr = [id]
        let sql = 'select * from tk_topup left join tkxq_topup on tk_id=tkxq_id where tk_id=?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '查询成功',
                data: data
            })
        })
    },
    steNodes(req, resp) {
        let { id, notes } = req.body
        let arr = [notes, id]
        console.log(arr);
        let sql = 'update tkxq_topup set tkxq_remark=? where tkxq_id=?'
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '备注成功',
                data: data
            })
        })
    },
    test(req, resp) {
        let { a } = req.query
        console.log(a);
        let arr = []
        console.log(arr);
        let sql = 'select * from cz_topup '
        db.f_DBConnection(resp, sql, arr, function (data) {
            resp.send({
                code: 200,
                msg: '备注成功',
                data: data
            })
        })
    },
}